<?php
/**
 * Author: 孙武 QQ:1228746736
 * Date: 2018/3/3
 * Time: 13:01
 */


/*
 * 定义:
 * 1 变量方法:小驼峰
 * 2 方法中:api:ajax调用  没有api:程序调用
 * 3
 *
 */

/**
 * Class Err 错误码统一定义类
 * @package app\controller
 */
class Err
{
    private $errno;
    private $errmsg;
    private $data;
    private $errRule = [
        "-1" => '系统繁忙,请稍后再试',
        '0' => "ok",
        '10000' => '暂无数据'
    ];

    public function info($errno = 0, $data = false)
    {
        $this->errno  = (int)$errno;
        $this->errmsg = $this->getErrmsg();
        $this->data   = $data;
        if ($data !== false && empty($data)) {
            return $this->infoEmpty();
        } else {
            return [
                'errno' => $this->errno,
                'errmsg' => $this->errmsg,
                'data' => $this->data
            ];
        }

    }

    public function getErrmsg()
    {
        return $this->errRule[(string)($this->errno)];
    }

    public function infoEmpty()
    {
        $this->errno = 10000;
        return [
            'errno' => $this->errno,
            'errmsg' => $this->getErrmsg(),
        ];
    }

    public function infoUpd($save)
    {
        if ($save > 0) {
            return $this->info(0);
        } else {
            return $this->info(-1);
        }
    }

}


class Helper
{
    public static function getA1ToZ1()
    {
        $arr=[];
        foreach (range('A',"Z") as $v){
            $v=(string)$v.(string)'1';
            array_push($arr,$v);

        }
        return $arr;
    }
    public static function getA2ToZ2()
    {
        $arr=[];
        foreach (range('A',"Z") as $v){
            $v=(string)$v.(string)'2';
            array_push($arr,$v);

        }
        return $arr;
    }
}